#include "LightCircuit.h"
#include "Service.h"

LightCircuit::LightCircuit(IArduino& arduino, MessageRouter& router, const String& name, ILogger& logger, int pin) : 
Service(arduino, router, name, logger), pin_(pin){
	arduino_.pin(pin_, arduino_.OUT());
	arduino_.dWrite(pin_, arduino.HIGHVAL());
}
bool LightCircuit::onItem(const String& name, const String& value){
	if(name == F("cmd") && value == F("light")){
		return true;
	}
	if(name == F("id") && value == name_){
		return true;
	}
	if(name == F("state")){
		if(value == F("on")){
			arduino_.dWrite(pin_, arduino_.LOWVAL());
		} else if(value == F("off")){
			arduino_.dWrite(pin_, arduino_.HIGHVAL());
		}
	}
	return false;
}